sbit DQ = P3^7;

void Init_Ds18b20()
{
	DQ = 1;                   
	delay5us();               
	DQ = 0;
	delay500us();
	delay50us();
	delay50us();
	delay50us();
	delay50us();
	delay10us();
	delay10us();        
	DQ = 1;
	delay500us();    
}

unsigned char Read_One_Byte()  
{
	unsigned char i = 0;
	unsigned char dat = 0;
	for(i = 8; i > 0; i--)
	{
		DQ = 0;             
		_nop_();                
		dat = (dat >> 1);             
		DQ = 1;             
		delay10us();            
		if(DQ)                  
		{
			dat = (dat | 0x80);           
		}             
		delay10us();             
		delay10us();             
		delay10us();             
		}
	return (dat);
}

void Write_One_Byte(unsigned char dat)
{
	unsigned char i = 0;
	for(i = 8; i > 0; i--)
	{
		DQ = 0;             
		_nop_(); 
		DQ = (dat & 0x01);                
		delay10us();             
		delay10us();             
		delay10us();            
		DQ = 1;                     
		dat = (dat >> 1);             
		delay10us(); 
	}
}

unsigned int Get_Tmp()
{
	unsigned char a, b;
	Init_Ds18b20();              
	Write_One_Byte(0xCC);        
	Write_One_Byte(0x44);       
	Init_Ds18b20();                
	Write_One_Byte(0xCC);         
	Write_One_Byte(0xBE);        
	a = Read_One_Byte();          
	b = Read_One_Byte();         
	return (((b << 8) | a) * 0.0625);
}